#!/usr/bin/python
# Generates gettext mo files for all sub-directories of a given
# directory

from os import walk, chdir, getcwd, system
from os.path import join as p_join
from sys import argv

if len(argv) != 2:
    print 'Usage:', argv[0], 'directory'
    print
    exit(1)

MSGFMT_LOCATION = '/usr/bin/msgfmt'
process_path = getcwd()

print argv[0], 'is generating .mo files using', MSGFMT_LOCATION
for root, dirs, files in walk(argv[1]):
    if '.svn' in dirs:
        dirs.remove('.svn')
    for filename in files:
        if filename.endswith('.po'):
            print 'Generated:', p_join(root, filename)
            system('%s -o %s %s' % (MSGFMT_LOCATION, p_join(root, filename.replace('.po', '.mo')),
                                    p_join(root, filename)))
